package cn.mazexal.exambg.services;

import cn.mazexal.exambg.common.models.PagedData;
import cn.mazexal.exambg.common.models.PagedResponse;
import cn.mazexal.exambg.common.models.SingleResponse;
import cn.mazexal.exambg.dataware.XmindLogMapper;
import cn.mazexal.exambg.models.converter.XmindLogConverter;
import cn.mazexal.exambg.models.db.XmindLogDO;
import cn.mazexal.exambg.models.qry.XmindQry;
import cn.mazexal.exambg.models.vo.XmindLogVO;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: Mazexal
 * Date: 2025/8/30
 */
@Service
public class ResourceService {

    @Resource
    private XmindLogConverter xmindLogConverter;

    @Resource
    private XmindLogMapper xmindLogMapper;


    public PagedData<XmindLogVO> getXmindLogList(XmindQry qry) {
        List<XmindLogDO> xmindLogDOList = xmindLogMapper.getXmindLogList(qry);
        int total = xmindLogMapper.getXmindLogCount(qry);
        return PagedData.of(qry, total, xmindLogDOList.stream().map(xmindLogConverter::toVO).toList());
    }

    public boolean addXmindLog(XmindLogVO xmindLogVO) {
        xmindLogVO.setCreateTime(System.currentTimeMillis());
        return xmindLogMapper.insert(xmindLogConverter.toDO(xmindLogVO)) > 0;
    }

    public boolean updateXmindLog(XmindLogVO xmindLogVO) {
        return xmindLogMapper.updateById(xmindLogConverter.toDO(xmindLogVO)) > 0;
    }

    public boolean deleteXmindLog(Long id) {
        return xmindLogMapper.deleteById(id) > 0;
    }
}
